# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: xguo

import coin.strategy.mm.feed_builder as feed
from coin.exchange.base.kr_rest.derivative_util import assert_expiry_str


def convert_symbol_to_product(symbol):
  splitted = symbol.split('.')
  assert len(splitted[0].split('-')) == 2, symbol
  try:
    assert_expiry_str(splitted[1])
    market_type = 'Futures'
    exchange = splitted[2]
  except AssertionError:
    market_type = 'Spot'
    exchange = splitted[1]

  if market_type == 'Spot':
    product_type = getattr(feed, exchange + 'Product')
    product_str = splitted[0]
  else:
    product_type = getattr(feed, exchange + 'FuturesProduct')
    product_str = '%s.%s' % (splitted[0], splitted[1])
  return product_type.FromStr(product_str)
